/*
 *
 *  *  Copyright © 2014 CIB Co.Ltd
 *  *  * All right reserved
 *  *  * Auther:jin xingwang
 *  *
 *
 */

package com.wsd.web;

import com.idf.domain.ManagerDTO;
import com.wsd.common.Result;
import com.wsd.common.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 接口
 * @author 靳兴旺
 * @version 1.0.0 2020-7-20
 * 业务层基类
 */
public class BaseController {

    @Autowired
    private TokenUtils tokenUtils;

    /**
     * 登陆时设置token
     * @param response
     */
    public void setToken(HttpServletResponse response, String notesId) {
        response.setHeader("Authorization", "Bearer "+ tokenUtils.createDefaultTokenStringRsa(notesId));
    }

    /**
     * 用户登陆设置token
     * @param response
     * @param openId
     * @param customerId
     */
    public void setToken(HttpServletResponse response, String openId, long customerId) {
        response.setHeader("Authorization", "Bearer "+ tokenUtils.createDefaultTokenStringRsa(openId, String.valueOf(customerId)));
    }

    /**
     * @author wjh
     * 将idf的接口返回的result转化为wsd的result
     * @param fromResult
     * @return toResult
     */
    public Result changeResult(com.idf.common.Result fromResult) {
        Result toResult = new Result();
        toResult.setResultCode(fromResult.getResultCode());
        toResult.setResultMsg(fromResult.getResultMsg());
        toResult.setData(fromResult.getData());
        return toResult;
    }

    /**
     * @author wjh
     * 将cif的接口返回的result转化为wsd的result
     * @param fromResult
     * @return toResult
     */
    public Result changeResult(com.cif.common.Result fromResult) {
        Result toResult = new Result();
        toResult.setResultCode(fromResult.getResultCode());
        toResult.setResultMsg(fromResult.getResultMsg());
        toResult.setData(fromResult.getData());
        return toResult;
    }

}
